home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Commands / Add CF StoredProc Variable.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  7.0 KB  |  238 lines

  1. // Copyright 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. var VAR_TYPE_LIST = null; 
  4. var CF_SQL_TYPE_LIST = null;
  5. var VAR_VALUE_FIELD = null;
  6. var VAR_TEST_VALUE_FIELD = null;
  7. var DB_VAR_NAME_FIELD = null;
  8. var CF_VAR_NAME_FIELD = null;
  9. var STORED_PROC_OBJ = null;
  10.  
  11. // *************** GLOBALS VARS *****************
  12.  
  13. var HELP_DOC = MM.cmdCFAddStoredProcVar; 
  14.  
  15.  
  16. //*************************API**************************
  17.  
  18. //--------------------------------------------------------------------
  19. // FUNCTION:
  20. //   commandButtons
  21. //
  22. // DESCRIPTION:
  23. //   Returns the array of buttons that should be displayed on the
  24. //   right hand side of the dialog.  The array is comprised
  25. //   of name, handler function name pairs.
  26. //
  27. // ARGUMENTS:
  28. //   none
  29. //
  30. // RETURNS:
  31. //   array of strings - name, handler function name pairs
  32. //--------------------------------------------------------------------
  33.  
  34. function commandButtons()
  35. {                          
  36.   return new Array(MM.BTN_OK,     "okClicked()",
  37.                    MM.BTN_Cancel, "cancelClicked()",
  38.                    MM.BTN_Help,   "displayHelp()" );
  39. }
  40.  
  41.  
  42. //--------------------------------------------------------------------
  43. // FUNCTION:
  44. //   okClicked
  45. //
  46. // DESCRIPTION:
  47. //   Sets the return value to the selected DSN and closes the window.
  48. //
  49. // ARGUMENTS:
  50. //   none
  51. //
  52. // RETURNS:
  53. //   nothing
  54. //--------------------------------------------------------------------
  55.  
  56. function okClicked()
  57. {
  58.   var dbVarName = DB_VAR_NAME_FIELD.value;
  59.   var varType = VAR_TYPE_LIST.get();
  60.   var cfSQLType = CF_SQL_TYPE_LIST.get();
  61.   // If varValue field is disabled, return empty value for it.
  62.   var varValue = (!VAR_VALUE_FIELD.getAttribute("disabled")) ? VAR_VALUE_FIELD.value : "";
  63.   // If varTestValue field is disabled, return empty value for it.
  64.   var varTestValue = (!VAR_TEST_VALUE_FIELD.getAttribute("disabled")) ? VAR_TEST_VALUE_FIELD.value : "";
  65.   // If cfVarName field is disabled, return empty value for it.
  66.   var cfVarName = (!CF_VAR_NAME_FIELD.getAttribute("disabled")) ? CF_VAR_NAME_FIELD.value : "";
  67.   var retArray = new Array(dbVarName, varType, cfSQLType, varValue, cfVarName, varTestValue); 
  68.   dwscripts.setCommandReturnValue(retArray);
  69.   window.close();
  70. }
  71.  
  72. //--------------------------------------------------------------------
  73. // FUNCTION:
  74. //   cancelClicked
  75. //
  76. // DESCRIPTION:
  77. //   Closes the window and returns nothing
  78. //
  79. // ARGUMENTS:
  80. //   none
  81. //
  82. // RETURNS:
  83. //   nothing
  84. //--------------------------------------------------------------------
  85.  
  86. function cancelClicked()
  87. {
  88.   dwscripts.setCommandReturnValue("");
  89.   window.close();
  90. }
  91.  
  92. //--------------------------------------------------------------------
  93. // FUNCTION:
  94. //   displayHelp
  95. //
  96. // DESCRIPTION:
  97. //   Displays the built-in Dreamweaver help.
  98. //
  99. // ARGUMENTS:
  100. //   none
  101. //
  102. // RETURNS:
  103. //   nothing
  104. //--------------------------------------------------------------------
  105.  
  106. function displayHelp()
  107. {
  108.   dwscripts.displayDWHelp(HELP_DOC);
  109. }
  110.  
  111. // ***************** LOCAL FUNCTIONS  ******************
  112. //--------------------------------------------------------------------
  113. // FUNCTION:
  114. //   updateUI
  115. //
  116. // DESCRIPTION:
  117. //   This function is called by the UI controls to handle UI updates
  118. //
  119. // ARGUMENTS:
  120. //   control - string - the name of the control sending the event
  121. //   event - string - the event which is being sent
  122. //
  123. // RETURNS:
  124. //   nothing
  125. //--------------------------------------------------------------------
  126.  
  127. function updateUI(control, event)
  128. {
  129.   if (control == "VarType")
  130.   {
  131.     var varType = VAR_TYPE_LIST.get();
  132.     switch (varType.toUpperCase())
  133.     {
  134.       case "IN":
  135.         CF_VAR_NAME_FIELD.setAttribute("disabled", "disabled");
  136.         VAR_VALUE_FIELD.removeAttribute("disabled");
  137.         VAR_TEST_VALUE_FIELD.removeAttribute("disabled");
  138.         break;
  139.       case "OUT":
  140.         CF_VAR_NAME_FIELD.removeAttribute("disabled");
  141.         VAR_VALUE_FIELD.setAttribute("disabled", "disabled");
  142.         VAR_TEST_VALUE_FIELD.setAttribute("disabled", "disabled");
  143.         break;
  144.       case "INOUT":
  145.         CF_VAR_NAME_FIELD.removeAttribute("disabled");
  146.         VAR_VALUE_FIELD.removeAttribute("disabled");
  147.         VAR_TEST_VALUE_FIELD.removeAttribute("disabled");
  148.         break;
  149.     } 
  150.     
  151.     if (   !CF_VAR_NAME_FIELD.getAttribute("disabled") && !CF_VAR_NAME_FIELD.value
  152.         && STORED_PROC_OBJ
  153.        )
  154.     {
  155.       CF_VAR_NAME_FIELD.value = STORED_PROC_OBJ.getUniqueVariableName("out_"
  156.                               + dwscripts.stripChars(DB_VAR_NAME_FIELD.value, "@"));
  157.     }
  158.   }
  159. }
  160.  
  161.  
  162. //--------------------------------------------------------------------
  163. // FUNCTION:
  164. //   initializeUI
  165. //
  166. // DESCRIPTION:
  167. //   This function is called in the onLoad event.  It is responsible
  168. //   for initializing the UI.  If we are inserting a recordset, this
  169. //   is a matter of populating the connection drop down.
  170. //
  171. //   If we are modifying a recordset, this is a matter of inspecting
  172. //   the recordset tag and setting all the form elements.
  173. //
  174. // ARGUMENTS:
  175. //   none
  176. //
  177. // RETURNS:
  178. //   nothing
  179. //--------------------------------------------------------------------
  180.  
  181. function initializeUI()
  182. {
  183.   // Initialize UI elements.
  184.   VAR_TYPE_LIST = new ListControl("VarType"); 
  185.   CF_SQL_TYPE_LIST = new ListControl("CFSQLType");
  186.   VAR_VALUE_FIELD = dwscripts.findDOMObject("Value"); 
  187.   VAR_TEST_VALUE_FIELD = dwscripts.findDOMObject("TestValue"); 
  188.   DB_VAR_NAME_FIELD = dwscripts.findDOMObject("DBVarName"); 
  189.   CF_VAR_NAME_FIELD = dwscripts.findDOMObject("CFVarName"); 
  190.  
  191.   // Grab the command arguments.
  192.   var theArgumentObj = dwscripts.getCommandArguments(); 
  193.  
  194.   var isEdit = false;
  195.   var dbVarName = "";
  196.   var varType = "";
  197.   var varValue = "";
  198.   var varTestValue = "";
  199.   var cfVarName = "";
  200.   var cfSQLType = ""; 
  201.   STORED_PROC_OBJ = null;
  202.   
  203.   if (theArgumentObj && theArgumentObj.length) 
  204.   {
  205.     isEdit = (theArgumentObj[0]) ? theArgumentObj[0] : false;
  206.     dbVarName = (theArgumentObj[1]) ? theArgumentObj[1] : "";
  207.     varType = (theArgumentObj[2]) ? theArgumentObj[2] : "";
  208.     varValue = (theArgumentObj[3]) ? theArgumentObj[3] : "";
  209.     cfVarName = (theArgumentObj[4]) ? theArgumentObj[4] : ""; 
  210.     cfSQLType = (theArgumentObj[5]) ? theArgumentObj[5] : ""; 
  211.     varTestValue = (theArgumentObj[6]) ? theArgumentObj[6] : ""; 
  212.     STORED_PROC_OBJ = (theArgumentObj[7]) ? theArgumentObj[7] : null;
  213.   }
  214.  
  215.   DB_VAR_NAME_FIELD.value = dbVarName;
  216.   if (isEdit)
  217.   {
  218.     DB_VAR_NAME_FIELD.setAttribute("disabled", "disabled");
  219.   }
  220.   else
  221.   {
  222.     DB_VAR_NAME_FIELD.removeAttribute("disabled");
  223.   }
  224.  
  225.   CF_VAR_NAME_FIELD.value = cfVarName; 
  226.   VAR_VALUE_FIELD.value = varValue;
  227.   VAR_TEST_VALUE_FIELD.value = varTestValue;
  228.   
  229.   var varTypes = ["IN", "OUT", "INOUT"];
  230.   VAR_TYPE_LIST.setAll(varTypes, varTypes);
  231.   VAR_TYPE_LIST.pickValue(varType.toUpperCase()); 
  232.   
  233.   var sqlTypes = STORED_PROC_OBJ.getCFSQLTypeList();
  234.   CF_SQL_TYPE_LIST.setAll(sqlTypes, sqlTypes);
  235.   CF_SQL_TYPE_LIST.pickValue(cfSQLType.toUpperCase());
  236.  
  237.   updateUI("VarType", "onChange");
  238. }